<?php
declare (strict_types=1);

namespace app\admin\controller\advertiser;

use app\admin\service\advertiser\AdvertiserPageService;
use app\admin\service\advertiser\AdvertiserTaskService;
use app\BaseController;
use think\facade\Request;
use think\response\Json;

/**
 * 广告主页面广告位
 */
class AdvertiserPage extends BaseController
{

    ######################################## 页面广告位管理 ##############################################
    /**
     * 页面广告位列表
     * @param AdvertiserPageService $advertiserPageService
     * @return Json
     */
    public function pageList(AdvertiserPageService $advertiserPageService): Json
    {
        $params['page'] = Request::param('page/d', 1);
        $params['limit'] = Request::param('limit/d', 10);
        $params['code'] = Request::param('code/s');
        $params['name'] = Request::param('name/s');
        $params['status'] = Request::param('status/d');
        return $advertiserPageService->pageList($params);
    }

    /**
     * 页面广告位添加
     * @param AdvertiserPageService $advertiserPageService
     * @return Json
     */
    public function pageAdd(AdvertiserPageService $advertiserPageService): Json
    {
        $params['code'] = Request::param('code/s');
        $params['name'] = Request::param('name/s');
        $params['pictures'] = Request::param('pictures/d');
        $params['example'] = Request::param('example/s');
        $params['desc'] = Request::param('desc/s');
        $params['status'] = Request::param('status/d', 1);
        $params['device_type'] = Request::param('device_type/a', []);
        return $advertiserPageService->pageAdd($params);
    }

    /**
     * 页面广告位编辑
     * @param AdvertiserPageService $advertiserPageService
     * @return Json
     */
    public function pageEdit(AdvertiserPageService $advertiserPageService): Json
    {
        $params['id'] = Request::param('id/d');
        $params['code'] = Request::param('code/s');
        $params['name'] = Request::param('name/s');
        $params['pictures'] = Request::param('pictures/d');
        $params['example'] = Request::param('example/s');
        $params['desc'] = Request::param('desc/s');
        $params['status'] = Request::param('status/d', 1);
        $params['device_type'] = Request::param('device_type/a', []);
        return $advertiserPageService->pageEdit($params);
    }

    /**
     * 页面广告位删除
     * @param AdvertiserPageService $advertiserPageService
     * @return Json
     */
    public function pageDel(AdvertiserPageService $advertiserPageService): Json
    {
        $params['id'] = Request::param('id/d');
        return $advertiserPageService->pageDel($params);
    }

    /**
     * 页面广告位状态
     * @param AdvertiserPageService $advertiserPageService
     * @return Json
     */
    public function pageStatus(AdvertiserPageService $advertiserPageService): Json
    {
        $params['id'] = Request::param('id/d');
        $params['status'] = Request::param('status/d');
        return $advertiserPageService->pageStatus($params);
    }

    ###################################### 页面广告位授权广告主 ################################################

    /**
     * 页面广告位授权广告主列表
     * @param AdvertiserPageService $advertiserPageService
     * @return Json
     */
    public function pageAuthList(AdvertiserPageService $advertiserPageService): Json
    {
        $params['page_id'] = Request::param('page_id/d', 0);
        $params['page'] = Request::param('page/d', 1);
        $params['limit'] = Request::param('limit/d', 10);
        return $advertiserPageService->pageAuthList($params);
    }

    /**
     * 页面广告位新增授权广告主
     * @param AdvertiserPageService $advertiserPageService
     * @return Json
     */
    public function pageAuthAdd(AdvertiserPageService $advertiserPageService): Json
    {
        $params['page_id'] = Request::param('page_id/d', 0);
        $params['ad_user_id'] = Request::param('ad_user_id/d', 0);
        $params['device_type'] = Request::param('device_type/a', []);
        return $advertiserPageService->pageAuthAdd($params);
    }

    /**
     * 页面广告位修改授权广告主
     * @param AdvertiserPageService $advertiserPageService
     * @return Json
     */
    public function pageAuthEdit(AdvertiserPageService $advertiserPageService): Json
    {
        $params['page_id'] = Request::param('page_id/d', 0);
        $params['ad_user_id'] = Request::param('ad_user_id/d', 0);
        $params['device_type'] = Request::param('device_type/a', []);
        return $advertiserPageService->pageAuthEdit($params);
    }

    /**
     * 页面广告位删除授权广告主
     * @param AdvertiserPageService $advertiserPageService
     * @return Json
     */
    public function pageAuthDel(AdvertiserPageService $advertiserPageService): Json
    {
        $params['page_id'] = Request::param('page_id/d', 0);
        $params['ad_user_id'] = Request::param('ad_user_id/d', 0);
        return $advertiserPageService->pageAuthDel($params);
    }

    ###################################### 页面广告位任务列表 ################################################

    /**
     * 页面广告位任务待审核列表
     * @param AdvertiserPageService $advertiserPageService
     * @return Json
     */
    public function pageReviewList(AdvertiserPageService $advertiserPageService): Json
    {
        $params['page'] = Request::param('page/d', 1);
        $params['limit'] = Request::param('limit/d', 10);
        $params['task_name'] = Request::param('task_name/s');
        $params['ad_user_id'] = Request::param('ad_user_id/d');
        $params['start_time'] = Request::param('start_time/d', 0);
        $params['end_time'] = Request::param('end_time/d', 0);
        $params['status'] = 2;
        return $advertiserPageService->pageTaskList($params);
    }

    /**
     * 页面广告位推广任务审核
     * @param AdvertiserTaskService $advertiserTaskService
     * @return Json
     */
    public function pageTaskReview(AdvertiserTaskService $advertiserTaskService): Json
    {
        $params['task_id'] = Request::param('task_id/d', 0);
        $params['status'] = Request::param('status/d', 2);
        return $advertiserTaskService->taskReview($params);
    }

    /**
     * 页面广告位推广任务列表
     * @param AdvertiserPageService $advertiserPageService
     * @return Json
     */
    public function pageTaskList(AdvertiserPageService $advertiserPageService): Json
    {
        $params['page'] = Request::param('page/d', 1);
        $params['limit'] = Request::param('limit/d', 10);
        $params['task_name'] = Request::param('task_name/s');
        $params['ad_user_id'] = Request::param('ad_user_id/d');
        $params['status'] = Request::param('status/d', 0);
        $params['start_time'] = Request::param('start_time/d', 0);
        $params['end_time'] = Request::param('end_time/d', 0);
        return $advertiserPageService->pageTaskList($params);
    }

    /**
     * 页面广告位推广任务上下架
     * @param AdvertiserTaskService $advertiserTaskService
     * @return Json
     */
    public function pageTaskEnable(AdvertiserTaskService $advertiserTaskService): Json
    {
        $params['task_id'] = Request::param('task_id/d', 0);
        $params['enable'] = Request::param('enable/d', 0);
        return $advertiserTaskService->taskEnable($params['task_id'], $params['enable']);
    }

}
